package com.huawang.mdesign.model.service.controller;

import com.huawang.business.util.ValidateDataUtil;
import com.huawang.business.vo.ModelResultVo;
import com.huawang.mdesign.model.service.request.uaf.CreateExchangeDto;
import com.huawang.mdesign.model.service.request.uaf.UpdateExchangeDto;
import com.huawang.mdesign.model.service.inter.UAFExchangeService;
import com.huawang.mdesign.model.service.vo.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * UAFExchange模型的操作控制器 Controller类
 */
@Tag(name = "交换")
@RestController
@RequestMapping("/exchange")
public class UAFExchangeController {

    private UAFExchangeService uafExchangeService;

    public UAFExchangeController(UAFExchangeService uafExchangeService) {
        this.uafExchangeService = uafExchangeService;
    }

    @Operation(summary = "创建交换")
    @PostMapping("/createExchange")
    public BaseResponse<ModelResultVo> createExchange(@RequestBody CreateExchangeDto createExchangeDto) {
        ValidateDataUtil.isNotEmpty(createExchangeDto.getProjectId());
        return BaseResponse.success(uafExchangeService.createExchange(createExchangeDto));
    }

    @Operation(summary = "更新交换")
    @PostMapping("/updateExchange")
    public BaseResponse<ModelResultVo> updateExchange(@RequestBody UpdateExchangeDto updateExchangeDto) {
        ValidateDataUtil.isNotEmpty(updateExchangeDto.getProjectId());
        return BaseResponse.success(uafExchangeService.updateExchange(updateExchangeDto));
    }

    @Operation(summary = "指定的模型是否可以被传输")
    @GetMapping("/canConveyed")
    public BaseResponse<Boolean> canConveyed(String projectId, String exchangeStereotype, String conveyedId) {
        return BaseResponse.success(uafExchangeService.canConveyed(projectId, exchangeStereotype, conveyedId));
    }

    @Operation(summary = "通过转换类型和传输模型获得exchangeKind")
    @GetMapping("/queryExchangeKindByConveyed")
    public BaseResponse<String> queryExchangeKindByConveyed(String projectId, String exchangeStereotype, String conveyedId) {
        return BaseResponse.success(uafExchangeService.queryExchangeKindByConveyed(projectId, exchangeStereotype, conveyedId));
    }
}
